package cn.dglydrpy.study.algorithm.od;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Yyy
 * @date 2024/11/6 11:43
 * @description  TODO
 * 题目描述：将 csv 格式数据文件中包含单元格引用的内容替换为对应单元格内容的实际值。
 */
public class Od0009_CSV {
    public static void main(String[] args) {
        
        String input = "";
        System.out.println(myAnswer(input));
        
    }

    private static String myAnswer(String input) {
        if(input == null){
            return "";
        }
        
        StringBuilder ans = new StringBuilder();
        String[] split = input.split(",");
        Map<Character,Info> map = new HashMap<>();
        for(int i=0;i<split.length;i++){
            map.put((char) ('A' + i),new Info(false,split[i]));
        }
        
        for(Map.Entry<Character,Info> entry : map.entrySet()){

            boolean parsed = entry.getValue().parsed;
            String value = entry.getValue().value;
            if(parsed){
                continue;
            }
            
            if(!value.contains("<")){
                entry.getValue().parsed = true;
            }else{

                char[] chars = value.toCharArray();
                Character key = null;
                int i = 0;
                for(Character c : chars){
                    if('<' == c){
                        key = chars[i+1];
                        Info info = map.get(key);
                        if(info.parsed){
                            
                        }
                    }
                    i++;
                }
            }
            
        }


        return ans.toString();
        
    }
    
    private static class Info{
        // 是否已完全解析
        private boolean parsed;

        // 单元格里的内容
        private String value;

        public Info(boolean parsed, String value) {
            this.parsed = parsed;
            this.value = value;
        }
    }
    
    // 解析某个单元格
    private Info process(Map<Character,Info> map,Character key){

        Info info = map.get(key);
        if(info == null){
            return new Info(false,"-1");
        }
        if(info.parsed){
            return info;
        }

        if(!info.value.contains("<")){
            info.parsed = true;
        }else{

            char[] chars = info.value.toCharArray();
            Character nkey = null;
            int i = 0;
            for(Character c : chars){
                if('<' == c){
                    nkey = chars[i+1];
                    Info nInfo = process(map, nkey);
                    if(nInfo.parsed){
                        
                    }
                }
                i++;
            }
        }

        return info;
    }


}
